'''
生成器
'''


def func1():
    print('===============')
    yield
    print('++++++++++++++++')


g = func1()
print(type(g))


def func2():
    yield 10
    yield 100
    yield 1000


g2 = func2()
for x in g2:
    print('x:', x)


def func3():
    print('1')
    yield 1
    print('2')
    yield 10
    print('3')
    yield 100


g3 = func3()
print(next(g3))


# 练习
def stu_no(pre, n):
    length = len(str(n))
    for i in range(1, n + 1):
        no = pre + str(i).zfill(length)
        yield no


g3 = stu_no('py', 120)
print(next(g3))
print(next(g3))
g4 = stu_no('h', 59)
print(next(g4))

g5 = (n for n in range(1, 10) if n & 1 == 0)
print(next(g5))
print(next(g5))
print(next(g5))
print(next(g5))
print(3%2)
